package dao

import (
	"daily-blog/global"
	"daily-blog/model"
)

func CreateCategory(category *model.Category) error {
	return global.GVA_DB.Create(category).Error
}
func DeleteCategoryById(categoryId string) error {
	return global.GVA_DB.Delete(&model.Category{}, "category_id=?", categoryId).Error
}
func GetCategoryList() (categoryList []model.CategoryInfo, err error) {
	err = global.GVA_DB.Model(&model.Category{}).Select("category_id", "name", "category_desc", "category_image").Find(&categoryList).Error
	return
}
func UpdateCategory(categoryId, categoryName, categoryDesc, categoryImage string) error {
	return global.GVA_DB.Model(&model.Category{}).Where("category_id=?", categoryId).Updates(&model.Category{Name: categoryName, CategoryDesc: categoryDesc, CategoryImage: categoryImage}).Error
}
